package com.smile.log;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smile.commons.page.MyBatisPlusPageConverter;
import com.smile.commons.page.R;
import com.smile.model.dto.request.AddOperateLogRequestDTO;
import com.smile.model.dto.request.GetOperateLogListRequestDTO;
import com.smile.model.response.response.GetOperateLogListResponseDTO;
import com.smile.request.AddOperateLogRequest;
import com.smile.request.GetOperateLogListRequest;
import com.smile.response.GetOperateLogListResponse;
import com.smile.service.OperateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/log/operate")
public class OperateLogController {

    @Autowired
    private OperateLogService operateLogService;

    @PostMapping("/addOperateLogRequest")
    public R<Void> addOperateLogRequest(@RequestBody AddOperateLogRequest addOperateLogRequest) {
        AddOperateLogRequestDTO addOperateLogRequestDTO = new AddOperateLogRequestDTO();
        BeanUtil.copyProperties(addOperateLogRequest, addOperateLogRequestDTO);
        Boolean result = operateLogService.addOperateLogRequest(addOperateLogRequestDTO);
        if (result) {

            return R.ok();
        } else {
            return R.fail();
        }
    }

    @PostMapping("/getOperateLogList")
    public R<Page<GetOperateLogListResponse>> getOperateLogList (@RequestBody GetOperateLogListRequest getOperateLogListRequest) {
        GetOperateLogListRequestDTO getOperateLogListRequestDTO = new GetOperateLogListRequestDTO();
        BeanUtil.copyProperties(getOperateLogListRequest, getOperateLogListRequestDTO);
        Page<GetOperateLogListResponseDTO> getOperateLogListResponseDTOPage = operateLogService.getOperateLogList(getOperateLogListRequestDTO);
        return R.ok(MyBatisPlusPageConverter.convertPage(getOperateLogListResponseDTOPage, GetOperateLogListResponse.class));
    }

}
